home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vidhandl / hextoi.c < prev    next >
Encoding:
Text File  |  1999-02-03  |  576 b   |  27 lines

  1. //This file is used by some of the examples of this subdirectory.
  2.  
  3. int hextoi (int *rtn, char *s)
  4. //converts a string (in hexadecimal notation) to integer
  5.  {
  6.     unsigned register a0; //return value
  7.     unsigned register a1; //auxiliar variable
  8.     a0=0;
  9.     while (*s)
  10.      {
  11.         a1=toupper (*s);
  12.         if(a1>='0' && a1<='9')
  13.             a1-='0';
  14.         if(a1>='A' && a1<='F')
  15.             a1-='7';
  16.         if (a1>16u)
  17.             return -1; //error in conversion
  18.         a0*=16u;
  19.         a0+=a1;
  20.         s++;
  21.      }
  22.     *rtn=a0;
  23.     return 0;
  24.  }
  25.  
  26. // rtn is the converted value.
  27. // hextoi returns 0 if sucessful. On error it returns -1.